
//列表数据
function barEVT(listData,ele){
	var max=0
	for(var i=0;i<listData.length;i++){
		if(max <= listData[i].value){
			max = listData[i].value;
		}
	}
	for(var i=0;i<listData.length;i++){
		listData[i].per=(listData[i].value/max)*100+"%"
	}
	for(var j=0;j<listData.length;j++){
		 $(ele).find(".barList").append("<li>"+
		   "<div style='color:#bed8e0'>"+(j+1)+"</div>"+
	       "<div style='color:#bed8e0'>"+listData[j].name+"</div>"+
	       "<div><p class='progressbar_1'>" +
	       "<span class='progress' style=width:"+listData[j].per+"></span>" +
	       	"</p></div>"+
	       "<div style='color:#bed8e0'>"+listData[j].value+"</div>"+
	       "</li>")
	}
}
var listData1=[
	{name:'浦东新区',value:74,per:0},
	{name:'宝山区',value:48,per:0},
	{name:'普陀区',value:33,per:0},
	{name:'徐汇区',value:22,per:0},
	{name:'静安区',value:15,per:0},
	{name:'闸北区',value:10,per:0},
	{name:'杨浦区',value:9,per:0},
	{name:'黄浦区',value:8,per:0},
	{name:'闵行区',value:7,per:0},
	{name:'松江区',value:4,per:0},
	{name:'长宁区',value:4,per:0},
	{name:'市辖区',value:4,per:0},
	{name:'嘉定区',value:4,per:0},
	{name:'虹口区',value:3,per:0},
	{name:'南汇区',value:2,per:0},
	{name:'青浦区',value:1,per:0},
	{name:'金山区',value:1,per:0}
	]
var listData2=[
	{name:'阿里云计算有限公司',value:2184238,per:0},
	{name:'阿里巴巴通信技术（北京）有限公司',value:69230,per:0},
	{name:'江苏邦宁科技有限公司',value:44469,per:0},
	{name:'上海呼啸信息科技发展有限公司',value:13998,per:0},
	{name:'厦门三五互联科技股份有限公司',value:8185,per:0}
]
var listData3=[
	{name:'中国电信股份有限公司上海分公司',value:122951},
	{name:'中国联合网络通信有限公司上海市分公司',value:57936},
	{name:'中国移动通信集团上海有限公司',value:38933}
]
barEVT(listData1,".proItem")
barEVT(listData2,".zzItem")
barEVT(listData3,".jcItem")

var geoCoordMap={}
var mapFeatures = echarts.getMap('上海').geoJson.features;
mapFeatures.forEach(function(v) {
    // 地区名称
    var name = v.properties.name;
    // 地区经纬度
    geoCoordMap[name] = v.properties.cp;
});

var convertData = function (data) {
    var res = [];
    for (var i = 0; i < data.length; i++) {
        var geoCoord = geoCoordMap[data[i].name];
        if (geoCoord) {
            res.push({
                name: data[i].name,
                value: geoCoord.concat(data[i].value)
            });
        }
    }
    console.log(res)
    return res;
};

var data = [
	{name:'浦东新区',value:74},
	{name:'宝山区',value:47},
	{name:'普陀区',value:33},
	{name:'徐汇区',value:22},
	{name:'静安区',value:15},
	{name:'闸北区',value:10},
	{name:'杨浦区',value:9},
	{name:'黄浦区',value:8},
	{name:'闵行区',value:7},
	{name:'松江区',value:4},
	{name:'长宁区',value:4},
	{name:'嘉定区',value:4},
	{name:'虹口区',value:3},
	{name:'南汇区',value:2},
	{name:'青浦区',value:1},
	{name:'崇明县',value:0},
	{name:'金山区',value:0},
	{name:'奉贤区',value:0}
];
var mapChart = echarts.init(document.getElementById('ec_map_nd'))
mapChart.setOption(getOptionMap(data,74,'企业'))
function getOptionMap(data,max,type){
	var optionMap = {
			tooltip: {
				trigger: 'item',
				formatter:function(param){
					var province = param.name;
						return	'<div>'+param.name+'</div>' +
					        '<div>'+type+'数量：'+param.data.value[2]+'</div>';
				}
			},
			geo: {
				show: true,
				zoom: 1.2,
				roam: false,
				map: '上海',
				itemStyle: {
					normal: {
						show: false,
						borderColor: '#285ac6',
						borderWidth: 1,
						areaColor: '#123082',
						shadowBlur: 3,
						shadowColor: '#081435',
						shadowOffsetX: -4,
						shadowOffsetY: 8
					},
					emphasis: {
						areaColor: '#fce24f',
						borderColor: '#fce24f'
					}
				}
			},
			series: [{
				type: 'map',
					zoom: 1.2,
					mapType: '上海',
					//		geoIndex: 0,
					roam: false,
					label: {
						normal: {
							show: false,
							textStyle: {
								color: '#fff'
							}
						},
						emphasis: {
							show: true,
							textStyle: {
								color: '#fff'
							}
						}
					},
					itemStyle: {
						normal: {
							show: false,
							borderColor: '#3770ea',
							borderWidth: 1,
							areaColor: '#0f2d87'
						},
						emphasis: {
							areaColor: '#2a56bd',
							borderColor: '#2a56bd',
							//				opacity: 0.8,
						}
					},
				data:convertData(data)
			},{
			 	name: 'Top 5',
	      type: 'effectScatter',
	      zlevel: 1,
	      coordinateSystem: 'geo',
	      symbolSize: function (val) {
	          return val[2]/max*20+5
	      },
	      showEffectOn: 'render',
	      rippleEffect: {
	          brushType: 'stroke'
	      },
	      hoverAnimation: true,
	      label: {
	          normal: {
	//            formatter: '{b}',
			        position: 'right',
			        show: false
	          }
	      },
	      itemStyle: {
	          normal: {
	              color: '#f4e925',
	              shadowBlur: 10,
	              shadowColor: '#333'
	          }
	      },
	//    data: convertData(mapData)
				data:convertData(data.sort(function(a,b){
					return b.value-a.value
				}).slice(0,5))
			},{
			 	name: 'Top 5',
	      type: 'scatter',
	      zlevel: 1,
	      coordinateSystem: 'geo',
	      symbolSize: function (val) {
	//        return val*4+8;
					return val[2]/max*20+5
	      },
	      showEffectOn: 'render',
	      rippleEffect: {
	          brushType: 'stroke'
	      },
	      hoverAnimation: true,
	      label: {
	          normal: {
	//            formatter: '{b}',
			        position: 'right',
			        show: false
	          }
	      },
	      itemStyle: {
	          normal: {
	              color: '#f4e925',
	              shadowBlur: 10,
	              shadowColor: '#333'
	          }
	      },
	//    data: convertData(mapData)
				data:convertData(data.sort(function (a, b) {
	          return b.value - a.value;
	      }).slice(5))
			}]
		};
	return optionMap;
}


$(".mapChange").change(function(){
    var n = $(this).val();
    var option = null;
    var mapData = null;
    if(n=="企业"){
    	mapData = [
    		{name:'浦东新区',value:74},
    		{name:'宝山区',value:47},
    		{name:'普陀区',value:33},
    		{name:'徐汇区',value:22},
    		{name:'静安区',value:15},
    		{name:'闸北区',value:10},
    		{name:'杨浦区',value:9},
    		{name:'黄浦区',value:8},
    		{name:'闵行区',value:7},
    		{name:'松江区',value:4},
    		{name:'长宁区',value:4},
    		{name:'嘉定区',value:4},
    		{name:'虹口区',value:3},
    		{name:'南汇区',value:2},
    		{name:'青浦区',value:1},
    		{name:'崇明县',value:0},
    		{name:'金山区',value:0},
    		{name:'奉贤区',value:0}
    	];
    	option = getOptionMap(mapData,74,n);
    }else if(n=="机房"){
        mapData = [
        	{name:'浦东新区',value:98},
        	{name:'宝山区',value:57},
        	{name:'普陀区',value:39},
        	{name:'徐汇区',value:25},
        	{name:'静安区',value:17},
        	{name:'闸北区',value:12},
        	{name:'杨浦区',value:10},
        	{name:'黄浦区',value:8},
        	{name:'闵行区',value:6},
        	{name:'长宁区',value:4},
        	{name:'嘉定区',value:4},
        	{name:'松江区',value:4},
        	{name:'虹口区',value:3},
        	{name:'青浦区',value:2},
        	{name:'南汇区',value:2},
        	{name:'金山区',value:1},
        	{name:'崇明县',value:0},
        	{name:'奉贤区',value:0},
        ];
        option = getOptionMap(mapData,98,n);
        //optionMap.series[0].data= convertData(mapData);
    }else if(n=="域名"){
    	mapData = [
    		{name:'普陀区',value:124615},
    		{name:'青浦区',value:123268},
    		{name:'徐汇区',value:182954},
    		{name:'闸北区',value:87},
    		{name:'金山区',value:123268},
    		{name:'静安区',value:220435},
    		{name:'宝山区',value:2437620},
    		{name:'闵行区',value:14095},
    		{name:'黄浦区',value:123883},
    		{name:'松江区',value:37},
    		{name:'浦东新区',value:2466820},
    		{name:'虹口区',value:123273},
    		{name:'嘉定区',value:10},
    		{name:'市辖区',value:20},
    		{name:'南汇区',value:264},
    		{name:'长宁区',value:169},
    		{name:'杨浦区',value:123284},
    		{name:'崇明县',value:0},
        	{name:'奉贤区',value:0},
    	];
    	option = getOptionMap(mapData,2466820,n);
    }else if(n=="IP地址"){
    	mapData = [
    		{name:'普陀区',value:68263},
    		{name:'青浦区',value:2616},
    		{name:'徐汇区',value:172406},
    		{name:'闸北区',value:100003},
    		{name:'静安区',value:367023},
    		{name:'宝山区',value:514504},
    		{name:'金山区',value:28408},
    		{name:'闵行区',value:262},
    		{name:'黄浦区',value:10196},
    		{name:'松江区',value:5705},
    		{name:'浦东新区',value:17569999},
    		{name:'虹口区',value:7674},
    		{name:'嘉定区',value:8448},
    		{name:'南汇区',value:821},
    		{name:'长宁区',value:394},
    		{name:'杨浦区',value:6595707},
    		{name:'崇明县',value:0},
        	{name:'奉贤区',value:0},
    	];
    	option = getOptionMap(mapData,17569999,n);
    }
    //optionMap.series[1].data= mapData;
    mapChart.setOption(option);
})

window.addEventListener("resize", function () {
    mapChart.resize();
});
